// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import '../src/styles/index.scss'
import store from '@/store/store.js'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import VueAMap from 'vue-amap'
import ECharts from 'vue-echarts'
Vue.component('chart', ECharts)
Vue.use(VueAMap)
Vue.use(ElementUI)

// 初始化vue-amap
VueAMap.initAMapApiLoader({
  // 高德的key
  key: '6a204f2b675f32f8849ec4b6b7c21e5c',
  // 插件集合
  plugin: ['AMap.Autocomplete', 'AMap.PlaceSearch', 'AMap.Scale', 'AMap.OverView', 'AMap.ToolBar', 'AMap.MapType', 'AMap.PolyEditor', 'AMap.CircleEditor'],
  // 高德 sdk 版本，默认为 1.4.4
  v: '1.4.4'
})

Vue.config.productionTip = false
// 添加导航卫士
router.beforeEach((to, from, next) => {
  var token = localStorage.getItem('token')
  // 如果有token值,则想做什么就做什么
  if (token) {
    next()
  } else {
    // 如果访问是登录页，则不做阻止
    if (to.path === '/login') {
      next()
    } else {
      // 如果都没有，则跳回登录页
      next({
        path: '/login'
      })
    }
  }
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: {
    App
  },
  template: '<App/>',
  computed: {
    username  () {
      return store.state.username
    }
  }
})
